import { parse } from '@toml-tools/parser';

import { locEnd, locStart } from './loc';
import { print } from './printer';

// https://prettier.io/docs/en/plugins.html#languages
const languages = [
  {
    aceMode: 'toml',
    codemirrorMimeType: 'text/x-toml',
    codemirrorMode: 'toml',
    extensions: ['.toml'],
    filenames: ['Cargo.lock', 'Gopkg.lock'],
    language_id: 365,
    name: 'Toml',
    parsers: ['toml'],
    tmScope: 'source.toml',
    type: 'data',
    vscodeLanguageIds: ['toml'],
  },
];

// https://prettier.io/docs/en/plugins.html#parsers
const parsers = {
  toml: {
    astFormat: 'toml-cst',
    locEnd,
    locStart,
    parse: (text: string) => parse(text),
  },
};

// https://prettier.io/docs/en/plugins.html#printers
const printers = {
  'toml-cst': {
    print,
  },
};

export {
  languages,
  parsers,
  printers,
  // TODO: are any options/default options needed?
  //  - Prefer certain inline variants when possible?
  //  - Indent nested props?
};
